package ru.poomsae.isap.Offline.SystemCutoff

import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.RadioButton
import android.widget.RadioGroup
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.example.isap_wtf.Model.ParametrsISAP
import ru.poomsae.isap.R

class PresentetationOFF : AppCompatActivity() {

    var s = 20
    var r = 20
    var e = 20
    var pr: Double = 6.0
    var accy: Double = 4.0
    var tot: Double = 10.0
    var onlineConSys = ParametrsISAP.onlineConSys
    open var accyInt = 40
    var prInt = 60
    var str = ""
    var idsud = ""
    var mIDHost = ParametrsISAP.idHostServer
    var idvistuplenie = ParametrsISAP.idvistuplenie
    var numSud = ParametrsISAP.numSud
    var sudID = ParametrsISAP.sudID

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.presentation)
        accy = intent.getDoubleExtra("accuracyDouble", 4.0)
        val accyr = findViewById(R.id.accyr) as TextView
        accyr.setText(accy.toString())
        val decorView = window.decorView
        val uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN
        decorView.systemUiVisibility = uiOptions
        getSupportActionBar()?.hide()
        val send = findViewById(R.id.send) as Button

        send.setOnClickListener {
            val intent = Intent(this, SystemOfCutOFF::class.java)
            startActivity(intent)
            finish()
        }

        val sila = findViewById(R.id.sila) as RadioGroup
        val silaPres = findViewById(R.id.silaPres) as TextView
        val pres = findViewById(R.id.pres) as TextView
        val total = findViewById(R.id.total) as TextView
        sila.setOnCheckedChangeListener(
            RadioGroup.OnCheckedChangeListener { group, checkedId ->
                val radio: RadioButton = findViewById(checkedId)
                s = ((radio.text as String).toDouble() * (10).toDouble()).toInt()
                silaPres.setText(radio.text as String)
                pr = (s + r + e).toDouble()/(10).toDouble()
                pres.setText(pr.toString())
                tot = accy + pr
                total.setText(String.format("%.1f",tot))
            })

        val ener = findViewById(R.id.ener) as RadioGroup
        val enerPres = findViewById(R.id.enerPres) as TextView
        ener.setOnCheckedChangeListener(
            RadioGroup.OnCheckedChangeListener { group, checkedId ->
                val radio: RadioButton = findViewById(checkedId)
                e = ((radio.text as String).toDouble() * (10).toDouble()).toInt()
                enerPres.setText(radio.text as String)
                pr = (s + r + e).toDouble()/(10).toDouble()
                pres.setText(pr.toString())
                tot = accy + pr
                total.setText(String.format("%.1f",tot))
            })

        val rhyt = findViewById(R.id.ener) as RadioGroup
        val rhytmPres = findViewById(R.id.enerPres) as TextView
        rhyt.setOnCheckedChangeListener(
            RadioGroup.OnCheckedChangeListener { group, checkedId ->
                val radio: RadioButton = findViewById(checkedId)
                r = ((radio.text as String).toDouble() * (10).toDouble()).toInt()
                rhytmPres.setText(radio.text as String)
                pr = (s + r + e).toDouble()/(10).toDouble()
                pres.setText(pr.toString())
                tot = accy + pr
                total.setText(String.format("%.1f",tot))
            })

    }

}